package com.ruoyi.project.jiaqin.supplyclass.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import com.ruoyi.framework.web.domain.ZtreeStr;
import com.ruoyi.project.jiaqin.quotationclass.domain.QuotationClass;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.jiaqin.supplyclass.mapper.SupplyClassMapper;
import com.ruoyi.project.jiaqin.supplyclass.domain.SupplyClass;
import com.ruoyi.project.jiaqin.supplyclass.service.ISupplyClassService;
import com.ruoyi.common.utils.text.Convert;

/**
 * 供需类型Service业务层处理
 *
 * @author admin
 * @date 2021-01-28
 */
@Service
public class SupplyClassServiceImpl implements ISupplyClassService
{
    @Autowired
    private SupplyClassMapper supplyClassMapper;

    /**
     * 查询供需类型
     *
     * @param id 供需类型ID
     * @return 供需类型
     */
    @Override
    public SupplyClass selectSupplyClassById(String id)
    {
        return supplyClassMapper.selectSupplyClassById(id);
    }

    /**
     * 查询供需类型列表
     *
     * @param supplyClass 供需类型
     * @return 供需类型
     */
    @Override
    public List<SupplyClass> selectSupplyClassList(SupplyClass supplyClass)
    {
        return supplyClassMapper.selectSupplyClassList(supplyClass);
    }

    @Override
    public List<ZtreeStr> selectSupplyClassTree() {
        List<SupplyClass> list = supplyClassMapper.selectSupplyClassList(new SupplyClass());
        return initZtree(list);
    }

    /**
     * 新增供需类型
     *
     * @param supplyClass 供需类型
     * @return 结果
     */
    @Override
    public int insertSupplyClass(SupplyClass supplyClass)
    {
        supplyClass.setId(UUID.randomUUID().toString().replace("-",""));
        return supplyClassMapper.insertSupplyClass(supplyClass);
    }

    /**
     * 修改供需类型
     *
     * @param supplyClass 供需类型
     * @return 结果
     */
    @Override
    public int updateSupplyClass(SupplyClass supplyClass)
    {
        return supplyClassMapper.updateSupplyClass(supplyClass);
    }

    /**
     * 删除供需类型对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteSupplyClassByIds(String ids)
    {
        return supplyClassMapper.deleteSupplyClassByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除供需类型信息
     *
     * @param id 供需类型ID
     * @return 结果
     */
    @Override
    public int deleteSupplyClassById(String id)
    {
        return supplyClassMapper.deleteSupplyClassById(id);
    }

    @Override
    public List<ZtreeStr> initZtree(List<SupplyClass> qcList) {
        List<ZtreeStr> ztrees = new ArrayList<ZtreeStr>();
        for (SupplyClass qc : qcList) {
            ZtreeStr ztree = new ZtreeStr();
            ztree.setId(qc.getId());
            ztree.setpId(qc.getParentId());
            ztree.setName(qc.getName());
            ztree.setTitle(qc.getName());
            ztrees.add(ztree);
        }
        return ztrees;
    }
}
